#include "stdafx.h"

Camera::Camera(glm::vec3 pos, glm::vec3 target, glm::vec3 up)
{
	this->pos = pos;
	this->target = glm::normalize(target);
	this->m_up = glm::normalize(up);
}

void Camera::forward(float dis)
{
	pos += target*dis;
}

void Camera::backward(float dis)
{
	pos -= target*dis;
}

void Camera::right(float dis)
{
	glm::vec3 r = glm::cross(target, m_up);

	pos += r*dis;
}

void Camera::left(float dis)
{
	glm::vec3 l = glm::cross(m_up, target);

	pos += l*dis;
}

glm::mat4 Camera::getView()
{
	return glm::lookAt(pos, pos + target, m_up);
}

void Camera::pitch(float angle)
{
	glm::vec3 r = glm::cross(target, m_up);

	target += m_up*tanf(angle);
	target = glm::normalize(target);

	m_up = glm::cross(r, target);
}

void Camera::yaw(float angle)
{
	glm::vec3 r = glm::cross(target, m_up);

	target += r*tanf(angle);
	target = glm::normalize(target);
}

void Camera::roll(float angle)
{
	glm::vec3 r = glm::cross(target, m_up);

	m_up += r*tanf(angle);
	m_up = glm::normalize(m_up);
}

void Camera::up(float dis)
{
	pos += m_up*dis;
}

void Camera::down(float dis)
{
	pos -= m_up*dis;
}